package com.seuic.hnjiningposapp.hnapps.ui.activity;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.cardview.widget.CardView;

import com.alibaba.fastjson.JSONObject;
import com.blankj.utilcode.util.SPStaticUtils;
import com.blankj.utilcode.util.ToastUtils;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.lxj.xpopup.XPopup;
import com.lxj.xpopup.core.BasePopupView;
import com.seuic.hnjiningposapp.R;
import com.seuic.hnjiningposapp.hnapps.base.BaseActivity;
import com.seuic.hnjiningposapp.hnapps.bean.BankDataBean;
import com.seuic.hnjiningposapp.hnapps.ui.view.dialog.AutomaticOperationPopup;
import com.seuic.hnjiningposapp.hnapps.ui.view.dialog.DealSuccessPopup;
import com.seuic.hnjiningposapp.hnapps.ui.view.dialog.DealingPopup;
import com.seuic.hnjiningposapp.hnapps.ui.view.dialog.DrawMoneyNumPopup;
import com.seuic.hnjiningposapp.hnapps.ui.view.dialog.ErrorPopup;
import com.seuic.hnjiningposapp.hnapps.ui.view.dialog.InputPasswordPopup;
import com.seuic.hnjiningposapp.hnapps.ui.view.dialog.InputPersonMsgPopup;
import com.seuic.hnjiningposapp.hnapps.ui.view.dialog.Input_nunname_moneyPp;
import com.seuic.hnjiningposapp.hnapps.ui.view.dialog.OtherBanKCaPp;
import com.seuic.hnjiningposapp.hnapps.ui.view.dialog.Other_cash_remitt_pp;
import com.seuic.hnjiningposapp.hnapps.ui.view.dialog.PrintingPopup;
import com.seuic.hnjiningposapp.hnapps.ui.view.dialog.RemittancePopup;
import com.seuic.hnjiningposapp.hnapps.ui.view.dialog.SureBankTrPp;
import com.seuic.hnjiningposapp.hnapps.ui.view.dialog.SurePrintPopup;
import com.seuic.hnjiningposapp.hnapps.ui.view.dialog.TrOtherSuccessPp;
import com.seuic.hnjiningposapp.hnapps.ui.view.dialog.VerifyCardPopup;
import com.seuic.hnjiningposapp.hnapps.util.DealMoneyAndNumComparisonUtils;
import com.seuic.hnjiningposapp.hnapps.util.GetMoneyLvUtils;
import com.seuic.hnjiningposapp.hnapps.util.HttpUtils;
import com.seuic.hnjiningposapp.hnapps.util.HttpUtilsV2;
import com.seuic.hnjiningposapp.hnapps.util.MoneyUtils;
import com.seuic.hnjiningposapp.hnapps.util.PrintUtil;
import com.seuic.hnjiningposapp.hnapps.util.TimeUtils;
import com.seuic.hnjiningposapp.hnapps.util.UiTool;
import com.seuic.posdsdk.pos_func.PosFuncs;
import com.socks.library.KLog;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * isjingkai
 * 2019年7月20日10:47:53
 * 转账汇款
 */

public class TransferActivity extends BaseActivity implements TrOtherSuccessPp.TrOtherSuccessPpCallBack, OtherBanKCaPp.otherBnakCappOk, ErrorPopup.OnFinishCallbacked, Other_cash_remitt_pp.onCallBack, SureBankTrPp.SureBankTrPpCallBack, Input_nunname_moneyPp.onInputNMMCallBack, RemittancePopup.ClickCallback, InputPasswordPopup.ClickCallback, DealSuccessPopup.ClickCallback, SurePrintPopup.ClickCallback, InputPersonMsgPopup.ClickCallback, DrawMoneyNumPopup.ClickCallback {

    @BindView(R.id.base_back_btn)
    LinearLayout baseBackBtn;
    @BindView(R.id.base_title_text)
    TextView baseTitleText;
    @BindView(R.id.re_select_ones_btn)
    Button reSelectOnesBtn;
    @BindView(R.id.re_select_others_btn)
    Button reSelectOthersBtn;
    @BindView(R.id.re_select_account_layout)
    LinearLayout reSelectAccountLayout;
    @BindView(R.id.local_layout)
    CardView localLayout;
    @BindView(R.id.input_rnum_edtext)
    EditText inputRnumEdtext;
    @BindView(R.id.inputnum_rname_edtext)
    EditText inputnumRnameEdtext;
    @BindView(R.id.sel_banname_ed)
    EditText selBannameEd;
    @BindView(R.id.search_bank)
    Button searchBank;
    @BindView(R.id.inputnum_rmoney_edtext)
    EditText inputnumRmoneyEdtext;
    @BindView(R.id.search_sxf)
    Button searchSxf;
    @BindView(R.id.sxf_tx)
    TextView sxfTx;
    @BindView(R.id.input_numokbtn)
    Button inputNumokbtn;
    @BindView(R.id.input_num_layout)
    LinearLayout inputNumLayout;


    private String time;
    boolean ones_Bnak = true;//是否本行交易
    //输入方式
    String input_type;
    //卡类型
    String CardType;
    //二磁信息
    String track2Data;
    //三磁信息
    String track3Data;
    //ic卡55信息
    String Field55;
    //银行卡号
    String card_num = "";
    private VerifyCardPopup verifycardPop;
    private BasePopupView verifycardPopupView;
    private RemittancePopup remittancePop;
    private BasePopupView remittancePopupView;
    private InputPasswordPopup inputpasswordPop;
    private BasePopupView inputpasswordPopupView;
    private DealingPopup dealingPop;
    private BasePopupView dealingPopupView;
    private DealSuccessPopup dealsuccessPop;
    private BasePopupView dealsuccessPopupView;
    private SurePrintPopup surePrintPop;
    private PrintingPopup printingPop;
    private BasePopupView printingPopupView;
    private BasePopupView surePrintPopupView;
    private String importmoney;
    private InputPersonMsgPopup inputpersonmsgPop;
    private BasePopupView inputpersonmsgPopupView;
    private DrawMoneyNumPopup drawmoneyNumPop;
    private BasePopupView drawmoneyNumPopupView;
    private AutomaticOperationPopup automaticOperationPopup;
    private BasePopupView automaticOperationPopupView;
    private Input_nunname_moneyPp input_nunname_moneyPp;
    private BasePopupView input_nunname_moneyPpView;
    private BasePopupView sureBankTrPpView;
    private SureBankTrPp sureBankTrPp;

    private Other_cash_remitt_pp other_cash_remitt_pp;
    private BasePopupView other_cash_remitt_ppview;
    private ErrorPopup errorPopup;
    private BasePopupView errorPopupPpView;

    //密码加密
    private String cipassword;

    //收款行行号
    private String openBrcNo;

    //输入账户信息 转入的账户信息
    private String join_card_num;
    private String join_username;
    private String join_money;

    //转出的卡号
    private String card_username;
    private String mServerSeqNo;
    private String make_time;

    //查询的银行名
    private String bankName = "";
    //查询的银行号
    private String bankNum;
    //手续费
    private String serviceCharge = "";


    private BasePopupView trOtherSuccessPpView;
    private TrOtherSuccessPp trOtherSuccessPp;


    @Override
    public int initView(Bundle savedInstanceState) {
        return R.layout.activity_transfer;
    }


    @Override
    public void initData(Bundle savedInstanceState) {
        this.setTitleText("转账汇款");
        findViewById(R.id.base_back_btn).setVisibility(View.INVISIBLE);
        trOtherSuccessPp = new TrOtherSuccessPp(this, this);
        trOtherSuccessPpView = new XPopup.Builder(this)
                .dismissOnBackPressed(false)
                .dismissOnTouchOutside(false)
                .moveUpToKeyboard(false)
                .isRequestFocus(false)
                .hasShadowBg(false)
                .hasStatusBarShadow(false)
                .asCustom(trOtherSuccessPp);

        errorPopup = new ErrorPopup(this, this);
        errorPopupPpView = new XPopup.Builder(this)
                .dismissOnBackPressed(false)
                .dismissOnTouchOutside(false)
                .moveUpToKeyboard(false)
                .isRequestFocus(false)
                .hasShadowBg(false)
                .hasStatusBarShadow(false)
                .asCustom(errorPopup);


        sureBankTrPp = new SureBankTrPp(this, this);
        sureBankTrPpView = new XPopup.Builder(this)
                .dismissOnBackPressed(false)
                .dismissOnTouchOutside(false)
                .moveUpToKeyboard(false)
                .isRequestFocus(false)
                .hasShadowBg(false)
                .hasStatusBarShadow(false)
                .asCustom(sureBankTrPp);
        input_nunname_moneyPp = new Input_nunname_moneyPp(this, TransferActivity.this, this);
        input_nunname_moneyPpView = new XPopup.Builder(this)
                .dismissOnBackPressed(false)
                .dismissOnTouchOutside(false)
                .moveUpToKeyboard(false)
                .isRequestFocus(false)
                .hasShadowBg(false)
                .hasStatusBarShadow(false)
                .asCustom(input_nunname_moneyPp);//验证账户信息界面

        verifycardPop = new VerifyCardPopup(this, this);
        verifycardPopupView = new XPopup.Builder(this)
                .dismissOnBackPressed(false)
                .dismissOnTouchOutside(false)
                .moveUpToKeyboard(false)
                .isRequestFocus(false)
                .hasShadowBg(false)
                .hasStatusBarShadow(false)
                .asCustom(verifycardPop);//验证账户信息界面
        remittancePop = new RemittancePopup(this, this, this);
        remittancePopupView = new XPopup.Builder(this)
                .dismissOnBackPressed(false)
                .dismissOnTouchOutside(false)
                .moveUpToKeyboard(false)
                .isRequestFocus(false)
                .hasShadowBg(false)
                .hasStatusBarShadow(false)
                .asCustom(remittancePop);//输入+核对汇款信息界面
        inputpasswordPop = new InputPasswordPopup(this, this);
        inputpasswordPopupView = new XPopup.Builder(this)
                .dismissOnBackPressed(false)
                .dismissOnTouchOutside(false)
                .moveUpToKeyboard(false)
                .isRequestFocus(false)
                .hasShadowBg(false)
                .hasStatusBarShadow(false)
                .asCustom(inputpasswordPop);//输入密码界面
        dealingPop = new DealingPopup(this, this);
        dealingPopupView = new XPopup.Builder(this)
                .dismissOnBackPressed(false)
                .dismissOnTouchOutside(false)
                .moveUpToKeyboard(false)
                .isRequestFocus(false)
                .hasShadowBg(false)
                .hasStatusBarShadow(false)
                .asCustom(dealingPop);//交易中界面
        dealsuccessPop = new DealSuccessPopup(this, this, this);
        dealsuccessPopupView = new XPopup.Builder(this)
                .dismissOnBackPressed(false)
                .dismissOnTouchOutside(false)
                .moveUpToKeyboard(false)
                .isRequestFocus(false)
                .hasShadowBg(false)
                .hasStatusBarShadow(false)
                .asCustom(dealsuccessPop);//交易成功界面
        surePrintPop = new SurePrintPopup(this, this, this);
        surePrintPopupView = new XPopup.Builder(this)
                .dismissOnBackPressed(false)
                .dismissOnTouchOutside(false)
                .moveUpToKeyboard(false)
                .isRequestFocus(false)
                .hasShadowBg(false)
                .hasStatusBarShadow(false)
                .asCustom(surePrintPop);//打印纸是否正常界面
        printingPop = new PrintingPopup(this, this);
        printingPopupView = new XPopup.Builder(this)
                .dismissOnBackPressed(false)
                .dismissOnTouchOutside(false)
                .moveUpToKeyboard(false)
                .isRequestFocus(false)
                .hasShadowBg(false)
                .hasStatusBarShadow(false)
                .asCustom(printingPop);//打印中界面
        inputpersonmsgPop = new InputPersonMsgPopup(this, this, this);
        inputpersonmsgPopupView = new XPopup.Builder(this)
                .dismissOnBackPressed(false)
                .dismissOnTouchOutside(false)
                .moveUpToKeyboard(false)
                .isRequestFocus(false)
                .hasShadowBg(false)
                .hasStatusBarShadow(false)
                .asCustom(inputpersonmsgPop);//输入转入行人员信息
        drawmoneyNumPop = new DrawMoneyNumPopup(this, this, this);
        drawmoneyNumPopupView = new XPopup.Builder(this)
                .dismissOnBackPressed(false)
                .dismissOnTouchOutside(false)
                .moveUpToKeyboard(false)
                .isRequestFocus(false)
                .hasShadowBg(false)
                .hasStatusBarShadow(false)
                .asCustom(drawmoneyNumPop);//输入取款金额界面
    }

    @Override
    public void initEvent(Bundle savedInstanceState) {
        this.setBackBtClick(R.id.base_back_btn);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }

    @OnClick({R.id.search_bank, R.id.search_sxf, R.id.input_numokbtn, R.id.re_select_ones_btn, R.id.re_select_others_btn})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.re_select_ones_btn:
                //点击选择了转本行账户
                reSelectAccountLayout.setVisibility(View.GONE);
                localLayout.setVisibility(View.GONE);
                readcardstart();//读卡操作
                break;
            case R.id.re_select_others_btn:
                ones_Bnak = false;
                reSelectAccountLayout.setVisibility(View.GONE);
                localLayout.setVisibility(View.GONE);
                readcardstart();//读卡操作
                break;
            case R.id.input_numokbtn:
                //确定跨行转账按钮
                if (serviceCharge.equals("")) {
                    ToastUtils.showLong("请查询手续费");
                    return;
                }
                if (bankName.equals("")) {
                    ToastUtils.showLong("请查询银行名");
                    return;
                }

                other_cash_remitt_pp = new Other_cash_remitt_pp(this, this);
                other_cash_remitt_ppview = new XPopup.Builder(this)
                        .dismissOnBackPressed(false)
                        .dismissOnTouchOutside(false)
                        .moveUpToKeyboard(false)
                        .isRequestFocus(false)
                        .hasShadowBg(false)
                        .hasStatusBarShadow(false)
                        .asCustom(other_cash_remitt_pp);
                other_cash_remitt_pp.setDealBanknames(bankName);
                other_cash_remitt_pp.setDealUsernames(inputnumRnameEdtext.getText().toString().trim());
                other_cash_remitt_pp.setServicechargeS(GetMoneyLvUtils.getMoney(serviceCharge));
                other_cash_remitt_pp.setDealNums(inputRnumEdtext.getText().toString().trim());
                other_cash_remitt_pp.setDealMoneyS(GetMoneyLvUtils.getInputMoney(inputnumRmoneyEdtext.getText().toString().trim()));
                other_cash_remitt_pp.setDealtype("跨行转账");
                inputNumLayout.setVisibility(View.GONE);
                other_cash_remitt_ppview.show();
                break;
            case R.id.search_sxf:
                //查询手续费
                searchSxfs();
                break;
            case R.id.search_bank:
                //查询银行信息
                if (selBannameEd.getText().toString().trim().equals("")) {
                    ToastUtils.showLong("请输入银行信息");
                    return;
                }
                searchBanks();
                break;
        }

    }

    public static void hideSoftKeyboard(Activity activity) {
        View view = activity.getCurrentFocus();
        if (view != null) {
            InputMethodManager inputMethodManager = (InputMethodManager) activity.getSystemService(Activity.INPUT_METHOD_SERVICE);
            inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
        }
    }

    /**
     * 查询银行信息
     */
    private void searchBanks() {
        KLog.e("进行银行信息查询成功");
        showMakeHint("正在查询银行信息");
        //添加银行
        hideSoftKeyboard(TransferActivity.this);
        HttpUtilsV2.getQueryAliasBankCardInfo(selBannameEd.getText().toString().trim(), new HttpUtilsV2.NetCallBack() {
            @Override
            public void onSuccess(String ServerSeqNo, String ConsumerSeqNo, JSONObject rspBody) {
                String datainfo = rspBody.getString("PS_BK_GRP");
                Gson gson = new Gson();
                List<BankDataBean> bankDataBeans = gson.fromJson(datainfo, new TypeToken<ArrayList<BankDataBean>>() {
                }.getType());


                KLog.e(bankDataBeans.size() + "size");

                List<String> BankNames = new ArrayList<>();

                for (int i = 0; i < bankDataBeans.size(); i++) {
                    BankNames.add(bankDataBeans.get(i).getBankName());
                }

                String[] banknames = BankNames.toArray(new String[BankNames.size()]);

                runOnUiThread(() -> {
                    dismissshowMakeHint();

                    new XPopup.Builder(TransferActivity.this)
                            .asBottomList("请选择银行", banknames, (position, text) -> {
                                selBannameEd.setText(text);
                                bankName = text;
                                bankNum = bankDataBeans.get(position).getBankNo();
                            }).show();
                });
            }


            @Override
            public void onError(String code, String msg) {
                showErr(msg);
            }
        });
    }

    /**
     * 查询手续费
     */
    private void searchSxfs() {
        if (inputRnumEdtext.getText().toString().trim().equals("")) {
            ToastUtils.showLong("请输入您的汇款账号");
            return;
        }
        if (inputnumRmoneyEdtext.getText().toString().equals("")) {
            ToastUtils.showLong("请输入您的汇款金额");
            return;
        }
        if (bankNum.equals("")) {
            ToastUtils.showLong("请选择银行");
            return;
        }
        KLog.e("查询手续费");
        hideSoftKeyboard(TransferActivity.this);
        //查询交易次数交易金额
        showMakeHint("手续费查询...");
        HttpUtilsV2.getQueryServiceCharge(
                card_num,
                openBrcNo,
                bankNum,
                inputRnumEdtext.getText().toString().trim(),
                inputnumRmoneyEdtext.getText().toString(),
                new HttpUtilsV2.NetCallBack() {
                    @Override
                    public void onSuccess(String ServerSeqNo, String ConsumerSeqNo1, JSONObject rspBody1) {
                        runOnUiThread(() -> {
                            dismissshowMakeHint();
                            serviceCharge = rspBody1.getString("ServiceFee");
                            sxfTx.setText("手续费 :" + GetMoneyLvUtils.getMoney(serviceCharge));
                        });
                    }

                    @Override
                    public void onError(String code, String msg) {
                        showErr(msg);
                    }
                });
    }

    /**
     * 读卡
     */
    private void readcardstart() {
        readCard(new HttpUtils.BaseReadCardListener() {
            @Override
            public void onSuccess(String data, String track2Data) {
                card_num = data;
                verifycardPopupView.show();
                //data  本行卡数据
                //返回成功  输入密码ui

                HttpUtilsV2.getCheckingThisBank(data, new HttpUtilsV2.NetCallBack() {
                    @Override
                    public void onSuccess(String ServerSeqNo, String ConsumerSeqNo, JSONObject rspBody) {
                        runOnUiThread(() -> {
                            KLog.e("进行账户验证通过,显示输入密码界面");
                            verifycardPopupView.dismiss();
                            if (!inputpasswordPopupView.isShow()) {
                                inputpasswordPopupView.show();
                            }
                        });
                    }

                    @Override
                    public void onError(String code, String msg) {
                        showErr(msg);
                    }
                });
            }

            @Override
            public void onError(String msg) {
                showErr(msg);
//                finish();
            }
        });
    }

    private void showErr(String msg) {
        runOnUiThread(() -> {
            errorPopup.setMsg(msg);
            errorPopupPpView.show();
        });
    }


    @Override
    public void OKRemittance(String money) {//核对信息后的钱数返回
        ToastUtils.showLong("核对信息后的钱数" + money);
        importmoney = money;
        remittancePopupView.dismiss();
        if (!inputpasswordPopupView.isShow()) {
            inputpasswordPopupView.show();
        }
    }

    @Override
    public void SendPassword(String password) {//返回输入的密码
        cipassword = HttpUtils.getResult(password, card_num);

        inputpasswordPopupView.dismiss();
//        if (!inputpersonmsgPopupView.isShow()) {
//            inputpersonmsgPopupView.show();
////            dealingPopupView.dismiss();
////            if (!dealsuccessPopupView.isShow()) {
////                dealsuccessPopupView.show();
////                dealsuccessPop.setContent(importmoney);
////            }
        doTrBank();
//        }
    }

    /**
     * 转账
     */
    private void doTrBank() {
        //弹出验证消息
        showMakeHint("验证密码...");
        HttpUtilsV2.getAccountPwdVerification(card_num, cipassword, new HttpUtilsV2.NetCallBack() {
            @Override
            public void onSuccess(String ServerSeqNo, String ConsumerSeqNo, JSONObject rspBody) {
                runOnUiThread(() -> {
                    KLog.e("验证密码通过，进行获取客户信息");
                    dismissshowMakeHint();
                    showMakeHint("获取客户信息...");
                    HttpUtilsV2.getQueryBankCardInfo(card_num, new HttpUtilsV2.NetCallBack() {
                        @Override
                        public void onSuccess(String ServerSeqNo, String ConsumerSeqNo, JSONObject rspBody) {
                            card_username = rspBody.getString("AcctName");
                            openBrcNo = rspBody.getString("OpenBrcNo");
                            runOnUiThread(() -> {
                                KLog.e("获取客户信息通过，进行黑名单验证");
                                dismissshowMakeHint();
                                showMakeHint("黑名单验证...");
                                HttpUtilsV2.getCheckingBankCardBlacklist(card_num, card_username, new HttpUtilsV2.NetCallBack() {
                                    @Override
                                    public void onSuccess(String ServerSeqNo, String ConsumerSeqNo, JSONObject rspBody) {
                                        runOnUiThread(() -> {
                                            KLog.e("黑名单验证通过，查询交易次数交易金额");
                                            dismissshowMakeHint();
                                            showMakeHint("查询交易次数交易金额...");
                                            HttpUtilsV2.getQueryAccountNorm(card_num, new HttpUtilsV2.NetCallBack() {
                                                @Override
                                                public void onSuccess(String ServerSeqNo, String ConsumerSeqNo, JSONObject rspBody) {
                                                    //验证密码成功
                                                    KLog.e("查询交易次数交易金额通过进行输入信息");
                                                    String TransferCount = rspBody.getString("TransferCount");
                                                    String TransferAmount = rspBody.getString("TransferAmount");
                                                    DealMoneyAndNumComparisonUtils.comparison(
                                                            DealMoneyAndNumComparisonUtils.REMITTANCE,
                                                            TransferCount,
                                                            TransferAmount, (next, msg) -> {
                                                                KLog.e(msg);
                                                                if (next) {
                                                                    runOnUiThread(() -> {
                                                                        dismissshowMakeHint();
                                                                        //弹出输入取款信息
                                                                        if (ones_Bnak) {
                                                                            input_nunname_moneyPp.setType("行内转账");
                                                                            input_nunname_moneyPpView.show();
                                                                        } else {
                                                                            //如果是 他行 请求手续费
                                                                            localLayout.setVisibility(View.GONE);
                                                                            inputNumLayout.setVisibility(View.VISIBLE);
                                                                        }
                                                                    });
                                                                } else {
                                                                    runOnUiThread(() -> {
                                                                        showErr(msg);
                                                                    });
                                                                }
                                                            });


                                                }

                                                @Override
                                                public void onError(String code, String msg) {
                                                    showErr(msg);
                                                }
                                            });
                                        });
                                    }

                                    @Override
                                    public void onError(String code, String msg) {
                                        showErr(msg);
                                    }
                                });
                            });
                        }

                        @Override
                        public void onError(String code, String msg) {
                            showErr(msg);
                        }
                    });
                });
            }

            @Override
            public void onError(String code, String msg) {
                runOnUiThread(() -> {
                    ToastUtils.showLong(msg);
                    dismissshowMakeHint();
                    inputpasswordPopupView = null;
                    inputpasswordPop = null;
                    inputpasswordPop = new InputPasswordPopup(TransferActivity.this, TransferActivity.this);
                    inputpasswordPopupView = new XPopup.Builder(TransferActivity.this)
                            .dismissOnBackPressed(false)
                            .dismissOnTouchOutside(false)
                            .moveUpToKeyboard(false)
                            .isRequestFocus(false)
                            .hasShadowBg(false)
                            .hasStatusBarShadow(false)
                            .asCustom(inputpasswordPop);//
                    inputpasswordPopupView.show();
                });
            }
        });
    }


    /**
     * 确认交易成功信息  开始打印
     */
    @Override
    public void OKPrint() {
        dealsuccessPopupView.dismiss();
        if (!surePrintPopupView.isShow()) {
            surePrintPopupView.show();
        }
    }

    /**
     * 确认打印纸安装 获取图标 开始打印
     */
    @Override
    public void ToPrint() {
        if (surePrintPopupView.isShow()) {
            surePrintPopupView.dismiss();


            if (!printingPopupView.isShow()) {
                printingPopupView.show();
//                paint();
//                PrintUtil.ThebankTransfer();

            }
            //请求电子印章
            HttpUtilsV2.getElectronicSeal("1", new HttpUtilsV2.NetCallBack() {
                @Override
                public void onSuccess(String ServerSeqNo, String ConsumerSeqNo, JSONObject rspBody) {
                    runOnUiThread(() -> {
                        if (ones_Bnak) {
                            //调用PrintUtil
                            PrintUtil.ThebankTransfer(PosFuncs.getInstace()
                                    , make_time,
                                    "行内转账",
                                    mServerSeqNo,
                                    card_username,
                                    card_num,
                                    join_username,
                                    join_card_num,
                                    MoneyUtils.packRequest(join_money),
                                    rspBody.getString("ImgBase64"), new PrintUtil.onPrintinterface() {
                                        @Override
                                        public void success(String success) {
                                            PrintUtil.ThebankTransfer2(PosFuncs.getInstace()
                                                    , make_time,
                                                    "行内转账",
                                                    mServerSeqNo,
                                                    card_username,
                                                    card_num,
                                                    join_username,
                                                    join_card_num,
                                                    MoneyUtils.packRequest(join_money),
                                                    rspBody.getString("ImgBase64"), new PrintUtil.onPrintinterface() {
                                                        @Override
                                                        public void success(String success) {
                                                            SPStaticUtils.put("ccsno", SPStaticUtils.getInt("ccsno", 1) + 1);
                                                            ToastUtils.showLong(success);
                                                            finish();
                                                        }

                                                        @Override
                                                        public void failed(String error) {
                                                            showErr(error);
                                                        }
                                                    });
                                        }

                                        @Override
                                        public void failed(String error) {
                                            showErr(error);
                                        }
                                    });
                        } else {
                            PrintUtil.ThebankTransfer(PosFuncs.getInstace()
                                    , make_time,
                                    "跨行转账",
                                    mServerSeqNo,
                                    card_username,
                                    card_num,
                                    inputnumRnameEdtext.getText().toString().trim(),
                                    inputRnumEdtext.getText().toString().trim(),
                                    GetMoneyLvUtils.getInputMoney(inputnumRmoneyEdtext.getText().toString().trim()),
                                    rspBody.getString("ImgBase64"), new PrintUtil.onPrintinterface() {
                                        @Override
                                        public void success(String success) {
                                            PrintUtil.ThebankTransfer2(PosFuncs.getInstace()
                                                    , make_time,
                                                    "跨行转账",
                                                    mServerSeqNo,
                                                    card_username,
                                                    card_num,
                                                    inputnumRnameEdtext.getText().toString().trim(),
                                                    inputRnumEdtext.getText().toString().trim(),
                                                    GetMoneyLvUtils.getInputMoney(inputnumRmoneyEdtext.getText().toString().trim()),
                                                    rspBody.getString("ImgBase64"), new PrintUtil.onPrintinterface() {
                                                        @Override
                                                        public void success(String success) {
                                                            SPStaticUtils.put("ccsno", SPStaticUtils.getInt("ccsno", 1) + 1);
                                                            ToastUtils.showLong(success);
                                                            finish();
                                                        }

                                                        @Override
                                                        public void failed(String error) {
                                                            showErr(error);
                                                        }
                                                    });
                                        }

                                        @Override
                                        public void failed(String error) {
                                            showErr(error);
                                        }
                                    });
                        }

                    });

                }

                @Override
                public void onError(String code, String msg) {
                    showErr(msg);
                }
            });
        }
    }

    @Override
    public void SendPersonMsg(String name, String num) {
        ToastUtils.showLong("人员姓名：" + name + "  账号：" + num);
        inputpersonmsgPopupView.dismiss();
        if (!drawmoneyNumPopupView.isShow()) {
            drawmoneyNumPopupView.show();
        }
    }

    @Override
    public void SendDrawMoneyNum(String money) {
        drawmoneyNumPopupView.dismiss();
        if (!dealingPopupView.isShow()) {
            dealingPopupView.show();
            dealingPopupView.dismiss();
            if (!dealsuccessPopupView.isShow()) {
                dealsuccessPopupView.show();
            }
        }
    }

    /**
     * 确定输入信息之后
     * 输入的卡号  输入的用户名  输入的金额
     */
    @Override
    public void onNext(String card_num, String user_name, String money) {
        join_card_num = card_num;
        join_username = user_name;
        join_money = money;
        input_nunname_moneyPpView.dismiss();
        sureBankTrPp.setType("行内转账");
        sureBankTrPp.setCardnum(card_num);
        sureBankTrPp.setMoney(money);
        sureBankTrPp.setUsername(user_name);
        sureBankTrPpView.show();
    }

    /**
     * 确认转账信息  上一步
     */
    @Override
    public void lastStep() {
        sureBankTrPpView.dismiss();
        input_nunname_moneyPp = null;
        input_nunname_moneyPpView = null;
        input_nunname_moneyPp = new Input_nunname_moneyPp(this, TransferActivity.this, this);
        input_nunname_moneyPpView = new XPopup.Builder(this)
                .dismissOnBackPressed(false)
                .dismissOnTouchOutside(false)
                .moveUpToKeyboard(false)
                .isRequestFocus(false)
                .hasShadowBg(false)
                .hasStatusBarShadow(false)
                .asCustom(input_nunname_moneyPp);//验证账户信息界面
        input_nunname_moneyPpView.show();
    }

    /**
     * 确认转账信息 下一步 本行
     */
    @Override
    public void next() {
        KLog.e("确认转账信息，进行转账");
        sureBankTrPpView.dismiss();
        dealingPopupView.show();


        //获取交易时间
        make_time = TimeUtils.getTimeData();
        HttpUtilsV2.getTransfer(card_num,
                card_username,
                join_card_num,
                join_username,
                openBrcNo,
                cipassword,
                join_money,
                "1", "", "100004", new HttpUtilsV2.NetCallBack() {
                    @Override
                    public void onSuccess(String ServerSeqNo, String ConsumerSeqNo, JSONObject rspBody) {
                        mServerSeqNo = ServerSeqNo;
                        KLog.e("进行行内转账,交易成功,显示成功界面");
                        runOnUiThread(() -> {
                            KLog.e("进行转账成功，显示转账结果");
                            dealingPopupView.dismiss();
                            trOtherSuccessPp.setMoney(GetMoneyLvUtils.getInputMoney(join_money));
                            trOtherSuccessPp.setName("行内转账");
                            trOtherSuccessPp.setUsername(card_username);
                            trOtherSuccessPp.setUserNum(card_num);
                            trOtherSuccessPp.setInjoinNum(join_card_num);
                            trOtherSuccessPp.setInjonName(join_username);
                            trOtherSuccessPpView.show();
                        });
                    }

                    @Override
                    public void onError(String code, String msg) {
                        showErr(msg);
                    }
                });

    }


    /**
     * 他行转账 确认信息 上一步
     */
    @Override
    public void Otherlaststep() {
        serviceCharge = "";
        sxfTx.setText("手续费");
        other_cash_remitt_ppview.dismiss();
        inputNumLayout.setVisibility(View.VISIBLE);
    }

    /**
     * 他行转账 确认信息 下一步
     */
    @Override
    public void OtherNext() {
        other_cash_remitt_ppview.dismiss();
        dealingPopupView.show();
        //获取交易时间
        make_time = TimeUtils.getTimeData();
        HttpUtilsV2.getTransfer(
                card_num,
                card_username,
                inputRnumEdtext.getText().toString().trim(),
                inputnumRnameEdtext.getText().toString().trim(),
                bankNum,
                cipassword,
                inputnumRmoneyEdtext.getText().toString().trim(),
                "2", serviceCharge, "100005", new HttpUtilsV2.NetCallBack() {
                    @Override
                    public void onSuccess(String ServerSeqNo, String ConsumerSeqNo, JSONObject rspBody) {
                        mServerSeqNo = ServerSeqNo;
                        KLog.e("进行行内转账,交易成功,显示成功界面");
                        runOnUiThread(() -> {
                            KLog.e("进行转账成功，显示转账结果");
                            dealingPopupView.dismiss();
                            trOtherSuccessPp.setMoney(GetMoneyLvUtils.getInputMoney(inputnumRmoneyEdtext.getText().toString().trim()));
                            trOtherSuccessPp.setName("跨行转账");
                            trOtherSuccessPp.setUsername(card_username);
                            trOtherSuccessPp.setUserNum(card_num);
                            trOtherSuccessPp.setInjoinNum(inputRnumEdtext.getText().toString().trim());
                            trOtherSuccessPp.setInjonName(inputnumRnameEdtext.getText().toString().trim());
                            trOtherSuccessPpView.show();
                        });
                    }

                    @Override
                    public void onError(String code, String msg) {
                        showErr(msg);
                    }
                });
    }

    @Override
    public void finished() {
        finish();
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }

    @Override
    public void OtherSureinfonext() {

    }

    @Override
    public void OnLast() {

    }

    /**
     * 确认他行转账成功界面
     */
    @Override
    public void OtherSuccessPpCall() {
        trOtherSuccessPpView.dismiss();
        surePrintPopupView.show();
    }
}
